package com.dhkj.printlib;

import android.content.Context;

import com.dhkj.printlib.entity.ThreePrintVo;
import com.dhkj.printlib.model.PayPrintBDModel;
import com.dhkj.printlib.model.PayPrintModel;
import com.dhkj.printlib.utils.sunmi.AidlUtil;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 小票打印
 */
public class PrintStart {
    private ExecutorService mExecutorService;
    private Context mContext;

    private PrintStart(Context context) {
        this.mContext = context;
        this.mExecutorService = Executors.newCachedThreadPool();
        AidlUtil.getInstance().connectPrinterService(mContext);
    }

    private static volatile PrintStart printStart = null;

    public static PrintStart with(Context context) {
        if (printStart == null) {
            synchronized (PrintStart.class) {

                if (printStart == null) {
                    printStart = new PrintStart(context);
                }
            }
        }
        return printStart;
    }

    public void printPay(ThreePrintVo threePrintVo) {
        PayPrintModel.prints(threePrintVo);
    }

    public void printPayBD(ThreePrintVo threePrintVo) {
        PayPrintBDModel.prints(threePrintVo);
    }

    public void printPP() {
        PrintUtils.clear();
        PrintUtils.selectCommand(PrintUtils.RESET);
        PrintUtils.selectCommand(PrintUtils.LINE_SPACING_DEFAULT);
        PrintUtils.selectCommand(PrintUtils.ALIGN_CENTER);
        PrintUtils.printText("美食餐厅\n\n");
        PrintUtils.selectCommand(PrintUtils.DOUBLE_HEIGHT_WIDTH);
        PrintUtils.printText("桌号：1号桌\n\n");
        PrintUtils.selectCommand(PrintUtils.NORMAL);
        PrintUtils.selectCommand(PrintUtils.ALIGN_LEFT);
        PrintUtils.printText(PrintUtils.printTwoData("订单编号", "201507161515\n"));
        PrintUtils.printText(PrintUtils.printTwoData("点菜时间", "2016-02-16 10:46\n"));
        PrintUtils.printText(PrintUtils.printTwoData("上菜时间", "2016-02-16 11:46\n"));
        PrintUtils.printText(PrintUtils.printTwoData("人数：2人", "收银员：张三\n"));

        PrintUtils.printText("--------------------------------\n");
        PrintUtils.selectCommand(PrintUtils.BOLD);
        PrintUtils.printText(PrintUtils.printThreeData("项目", "数量", "金额\n"));
        PrintUtils.printText("--------------------------------\n");
        PrintUtils.selectCommand(PrintUtils.BOLD_CANCEL);
        PrintUtils.printText(PrintUtils.printThreeData("面", "1", "0.00\n"));
        PrintUtils.printText(PrintUtils.printThreeData("米饭", "1", "6.00\n"));
        PrintUtils.printText(PrintUtils.printThreeData("铁板烧", "1", "26.00\n"));
        PrintUtils.printText(PrintUtils.printThreeData("一个测试", "1", "226.00\n"));
        PrintUtils.printText(PrintUtils.printThreeData("牛肉面啊啊", "1", "2226.00\n"));
        PrintUtils.printText(PrintUtils.printThreeData("牛肉面啊啊啊牛肉面啊啊啊", "888", "98886.00\n"));

        PrintUtils.printText("--------------------------------\n");
        PrintUtils.printText(PrintUtils.printTwoData("合计", "53.50\n"));
        PrintUtils.printText(PrintUtils.printTwoData("抹零", "3.50\n"));
        PrintUtils.printText("--------------------------------\n");
        PrintUtils.printText(PrintUtils.printTwoData("应收", "50.00\n"));
        PrintUtils.printText("--------------------------------\n");

        PrintUtils.selectCommand(PrintUtils.ALIGN_LEFT);
        PrintUtils.printText("备注：不要辣、不要香菜");
        PrintUtils.printText("\n\n\n\n\n");
        AidlUtil.getInstance().sendRawData(PrintUtils.outbyte);

    }
}
